//
//  HZWeathrView.m
//  MyDoctor
//
//  Created by 黑眼圈 on 16/5/4.
//  Copyright © 2016年 heiyan. All rights reserved.
//

#import "HZWeathrView.h"
//#import "HZWeatherModel.h"
//#import "HZWeatherSingleDayModel.h"

@interface HZWeathrView ()


@end


@implementation HZWeathrView



- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        
        //设置并添加子控件
        [self setupUI];
    }
    return self;
}

#pragma mark -
#pragma mark    设置并添加子控件
-(void)setupUI{
    
    //设置背景色  weatherBackgroundColor
        self.backgroundColor = [UIColor colorWithRed:182/255.0 green:241/255.0 blue:225/255.0 alpha:1];
//    self.backgroundColor = weatherBackgroundColor;
    
    //添加控件
    [self addSubview:self.iconImageView];
    [self addSubview:self.separateImageView];
    [self addSubview:self.weatherLabel];
    [self addSubview:self.cityLabel];
    [self addSubview:self.temperatureLabel];
    [self addSubview:self.dateLabel];
    
    //设置约束
    [self.iconImageView makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.left.equalTo(self).offset(20);
        make.width.equalTo(50);
        make.height.equalTo(50);
    }];
    
    [self.weatherLabel makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.iconImageView);
        make.left.equalTo(self.iconImageView.right).offset(20);
       
    }];
    
    [self.cityLabel makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.iconImageView);
        make.left.equalTo(self.weatherLabel.right).offset(20);
        
    }];
    
    [self.temperatureLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.centerX).offset(30);
        make.top.equalTo(self).offset(20);
    }];
    
    [self.dateLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.temperatureLabel.left);
        make.top.equalTo(self.temperatureLabel.bottom).offset(10);
    }];
    
    [self.separateImageView makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
        make.width.equalTo(2);
        make.height.equalTo(self.height).offset(-10);
    }];
    
    
    
    
}

#pragma mark -
#pragma mark 实现cityLabel的点击手势
-(void)cityLabelClick{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"cityLabelClick" object:nil];
}



#pragma mark -
#pragma mark 懒加载控件
/// 天气图标
///
/// @return <#return value description#>
-(UIImageView *)iconImageView{
    if (_iconImageView == nil) {
        
        _iconImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"sun"]];
        
        _iconImageView.contentMode = UIViewContentModeScaleAspectFill;
        
        _iconImageView.clipsToBounds = YES;
    }
    
    return _iconImageView;
}

/// 分割线图片
///
/// @return <#return value description#>
-(UIImageView *)separateImageView{
    if (_separateImageView == nil) {
        
        _separateImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"fengexian"]];
        
       
    }
    
    return _separateImageView;
    
}

/// 天气label
///
/// @return <#return value description#>
-(UILabel *)weatherLabel{
    if (_weatherLabel == nil) {
        _weatherLabel = [[UILabel alloc] init];
        
        _weatherLabel.textColor = weatherBackgroundColor;
//        _weatherLabel.textColor = [UIColor whiteColor];
        
        _weatherLabel.text = @"晴";
        
        [_weatherLabel sizeToFit];
        
    }
    
    return _weatherLabel;
}

/// 温度label
///
/// @return <#return value description#>
-(UILabel *)temperatureLabel{
    if (_temperatureLabel == nil) {
        _temperatureLabel = [[UILabel alloc] init];
        
        _temperatureLabel.textColor = weatherBackgroundColor;
        
        _temperatureLabel.text = @"温度:1~~14℃";
        
        [_temperatureLabel sizeToFit];
        
    }
    
    return _temperatureLabel;
}

/// 日期label
///
/// @return <#return value description#>
-(UILabel *)dateLabel{
    if (_dateLabel == nil) {
        _dateLabel = [[UILabel alloc] init];
        
        _dateLabel.textColor = weatherBackgroundColor;
        
        _dateLabel.text = @"2016-05-01";
        
        [_dateLabel sizeToFit];
        
    }
    
    return _dateLabel;
}

/// 城市按钮
///
/// @return <#return value description#>
-(UILabel *)cityLabel{
    if (_cityLabel == nil) {
        _cityLabel = [[UILabel alloc] init];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(cityLabelClick)];
        
        [_cityLabel addGestureRecognizer:tap];
        
        _cityLabel.textColor = weatherBackgroundColor;
        
        //加下划线
        NSMutableAttributedString *content = [[NSMutableAttributedString alloc] initWithString:@"上海"];
        
        [content addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, [content length])];
        
        _cityLabel.attributedText = content;

        
        [_cityLabel sizeToFit];
        
        
        
    }
    return _cityLabel;
}








@end
